package com.itheima.app.controller;

import com.itheima.app.manager.SoulManager;
import com.itheima.domain.mongo.Answer;
import com.itheima.vo.ReportVo;
import com.itheima.vo.SoulVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testSoul")
public class SoulController {

    @Autowired
   private SoulManager soulManager;


    //测灵魂  问卷列表
    @GetMapping
    public ResponseEntity<List<SoulVo>>  soulQustionsList(){

        try {

          List<SoulVo> soulVoList=  soulManager.soulQustionsList();
          return ResponseEntity.ok(soulVoList);
      } catch (Exception e){
          e.printStackTrace();
      }
      return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping
    public ResponseEntity<String> SaveSoulAnswer(@RequestBody Map<String,List<Answer>> answer){
        try {
           String reportId = soulManager.SaveSoulAnswer(answer);
           return ResponseEntity.ok(reportId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
    @GetMapping("/report/{id}")
    public  ResponseEntity<ReportVo> saveSoulAnswer(@PathVariable("id") String reportId){
        try {
         ReportVo reportVo=  soulManager.queryReport(reportId);
         return ResponseEntity.ok(reportVo);
        }catch (Exception e){
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
